$(document).ajaxSend(function (e,xhr,opt){
    let token=localStorage.getItem("user_token");
    xhr.setRequestHeader("user_header_token",token)
});
$(document).ajaxError(function (event,xhr,options,exc){
    if(xhr.status==401){
        alert("用户未登录");
        location.href="blog_login.html";
    }
})
function getUserInfo(url){
    $.ajax({
        type:"get",
        url:url,
        success:function (result){
            if(result!=null&&result.code==200&&result.data!=null){
                let userInfo=result.data;
                $(".card h3").text(userInfo.userName);
                $(".card a").attr("href",userInfo.githubUrl);
            }else {
                alert("获取用户信息失败");
            }
        }

    });
}

function logout(){
    let logout=confirm("确定退出登录吗？");
    if(logout){
        localStorage.removeItem("user_token");
        localStorage.removeItem("login_user_id");
        location.href="blog_login.html";
    }

}